home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_325 / fam / dibbsfamgrep.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  93 lines

  1. /*
  2.  * DibbsFamGrep.c
  3.  * Sample Complex FAMgrep code.
  4.  * This is the FAMgrep used by DIBBS.
  5.  */
  6.  
  7. /*****************************************************************
  8.  
  9. This FAMgrep takes four arguments. The first is a digit representing
  10. which type of GREP to perform and for now must always be zero. The second
  11. is the prefix of the filename. If the filename does not start with this
  12. prefix then DibbsGrep will return FALSE. The third is the line tag to look
  13. for. DibbsGrep will return FALSE if there is no line in the contents that
  14. starts with this string. The fourth is the value. If the line containing
  15. the indicated line tag does not contain the contents as a separate word
  16. then DibbsGrep will return FALSE. If the file name starts with argument two
  17. and it contains a line that starts with argument three and that line
  18. contains a word matching argument four then DibbsGrep returns true.
  19.  
  20. ******************************************************************/
  21.  
  22.  
  23. #include "exec/types.h"
  24. #include "FAM.h"
  25. #include "string.h"
  26.  
  27. long DibbsFamGrep(struct ScanListNode * node, char * p)
  28. {
  29.     char buf[256];
  30.     char * prefix, * tag, * word;
  31.     unsigned short i;
  32.  
  33.     /* first, parse the parameters */
  34.     while (*p && *p <= ' ') p += 1;
  35.     if (!*p) return 0;
  36.     if (*p++ != '0') return 0;    /* unknown grep type */
  37.  
  38.     while (*p && *p <= ' ') p += 1;
  39.     if (!*p) return 0;
  40.  
  41.     if (sizeof(buf) <= strlen(p)) return 0;
  42.     strcpy(buf, p);
  43.     prefix = p = buf;
  44.  
  45.     while (' ' < *p) p += 1;
  46.     if (*p == ' ')
  47.     *p++ = '\0';
  48.     else
  49.     return 0;
  50.  
  51.     tag = p;
  52.     while (' ' < *p) p += 1;
  53.     if (*p == ' ')
  54.     *p++ = '\0';
  55.     else
  56.     return 0;
  57.  
  58.     word = p;
  59.     while (' ' < *p) p += 1;
  60.     *p = '\0';
  61.  
  62.     /* Here, check if file fullfills requirements */
  63.  
  64.     if (0 != strncmp(prefix, node->node.ln_Name, strlen(prefix)))
  65.     return 0;
  66.  
  67.     i = strlen(tag);
  68.     for (p = node->contents; p != NULL; ) {
  69.     if (strncmp(p, tag, i) == 0)
  70.         break;
  71.     p = strchr(p, '\n');
  72.     if (p) p += 1;
  73.     }
  74.     if (p == NULL) return 0;
  75.  
  76.     i = strlen(word);
  77.     do {
  78.     while (*p && *p != ' ') p += 1;
  79.     while (*p == ' ') p += 1;
  80.     if (!*p) break;
  81.     if (0 == strncmp(p, word, i) &&
  82.         (p[i] == ' ' || p[i] == '\n' || p[i] == '\0')) {
  83.         return 1;    /* we found it! */
  84.         }
  85.     } while (1);    /* internal break gets us out */
  86.     return 0;    /* oh well. */
  87.  
  88.     }
  89.  
  90.  
  91.  
  92.  
  93.